package clientMain;

import lib.StreamSocket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @file Transmitter.java
 * 
 * @version 0.1
 * @author Chris Sewell 10008342
 */
public class Transmitter extends Thread {

	StreamSocket streamServer;
	Scanner scan;
	String serverInput;

	boolean debug;

	public Transmitter(StreamSocket serverStream, Scanner scan,
			String initialInput, boolean debug) {
		this.streamServer = serverStream;
		this.scan = scan;
		this.debug = debug;
		serverInput = Parser.parseRequest(initialInput, this.streamServer);
	}

	@Override
	public void run() {
		while (streamServer.isOpen()) {
			// Send string to server
			if ((debug == true) && (serverInput != "")) {
				System.out.print("Sent to: " + streamServer.displayDetail()
						+ "\n" + serverInput);
			}
			streamServer.sendString(serverInput);
			// Receive string from keyboard input
			serverInput = scan.nextLine();
			serverInput = Parser.parseRequest(serverInput, streamServer);
			try {
				Thread.sleep(50);
			} catch (InterruptedException ex) {
				Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE,
						null, ex);
			}

		}
	}

}
